package com.blog.controller;

import com.alibaba.fastjson.JSON;
import com.blog.pojo.Tag;
import com.blog.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Copyright (C), 2022
 * Author: 苏大大
 * Date: 2022-04-20 15:22
 * FileName: BaseController
 * Description:
 */
@Slf4j
public class BaseController {
    @Resource
    private RedisTemplate redisTemplate;
    //检查用户是否登录
    public  User checkUser(Long uid){
        if(redisTemplate.opsForValue().get(uid+"")!=null){
            String s =redisTemplate.opsForValue().get(uid+"").toString();
            User user=(User) JSON.parseObject(s,User.class);
            log.info("用户已登录,用户ID{}",user.getUid());
            return user;
        }
        log.info("用户未登录");
        return null;
    }
    public boolean logout(Long uid){
        redisTemplate.opsForValue().set(uid+"",null);
        if(redisTemplate.opsForValue().get(uid+"")==null){
            log.info("用户已退出登录");
            return true;
        }
        log.info("用户退出登录出现异常!");
        return false;
    }
}
